package com.mmlc.meimei.lichengkongjian.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;

import com.mmlc.inter.InterAdapter;
import com.mmlc.meimei.lichengkongjian.R;
import com.mmlc.network.responsebean.PrepareResponseBean;
import com.mmlc.utils.ViewUtils;

import java.util.List;

/**
 * Created by Administrator on 2016/12/7.
 */

public class SendAdapter extends InterAdapter<PrepareResponseBean.DataBean.DeliveryListBean> {


    public SendAdapter(Context context, List<PrepareResponseBean.DataBean.DeliveryListBean> datas) {
        super(context, datas);
    }

    int selectedMode = 0;

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null)
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_payment, parent, false);

        TextView tv_name = ViewUtils.getView(convertView, R.id.tv_payment);
        CheckBox checkbox_payment = ViewUtils.getView(convertView, R.id.checkbox_payment);

        if (!ViewUtils.isEmpty(datas.get(position).getName()))
            tv_name.setText(datas.get(position).getName());

        if (selectedMode == position)
            checkbox_payment.setChecked(true);
        else checkbox_payment.setChecked(false);

        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setSelectedMode(position);
            }
        });

        return convertView;
    }

    public int getSelectedMode() {
        return selectedMode;
    }

    public void setSelectedMode(int selectedMode) {
        this.selectedMode = selectedMode;
        notifyDataSetChanged();
    }
}
